<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="8">
            <a-form-model-item label="手机号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mobile">
              <a-input :disabled=formDisabled v-model="model.mobile" placeholder="请输入手机号码"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="固定电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fixedTel">
              <a-input :disabled=formDisabled v-model="model.fixedTel" placeholder="请输入固定电话"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="电子邮件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="email">
              <a-input :disabled=formDisabled v-model="model.email" placeholder="请输入电子邮件"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="身份证地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="idCardAddress">
              <a-input :disabled=formDisabled v-model="model.idCardAddress" placeholder="请输入身份证地址"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="邮政编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zipCode">
              <a-input :disabled=formDisabled v-model="model.zipCode" placeholder="请输入邮政编码"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="现居地详细地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currentAddress">
              <a-input :disabled=formDisabled v-model="model.currentAddress" placeholder="请输入现居地详细地址"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction } from '@/api/manage'

export default {
  name: 'ErpEmployeeContactInfoForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 },
      },
      confirmLoading: false,
      validatorRules: {
        officalTel: [
          { required: false },
          { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!' },
        ],
        mobile: [
          { required: false },
          { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码!' },
        ],
        email: [
          { required: false },
          { pattern: /^([\w]+\.*)([\w]+)@[\w]+\.\w{3}(\.\w{2}|)$/, message: '请输入正确的电子邮件!' },
        ],
        zipCode: [
          { required: false },
          { pattern: /^[1-9]\d{5}$/, message: '请输入正确的邮政编码!' },
        ],
        personalPage: [
          { required: false },
          {
            pattern: /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:\/~+#]*[\w\-@?^=%&\/~+#])?$/,
            message: '请输入正确的网址!'
          },
        ],
        blogLink: [
          { required: false },
          {
            pattern: /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:\/~+#]*[\w\-@?^=%&\/~+#])?$/,
            message: '请输入正确的网址!'
          },
        ],
      },
      url: {
        add: '/api/erp/files/employee/erpEmployeeContactInfo/add',
        edit: '/api/erp/files/employee/erpEmployeeContactInfo/edit',
        queryById: '/api/erp/files/employee/erpEmployeeContactInfo/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      this.$refs.form.resetFields();
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  }
}
</script>
